package android.alliance.inappbilling;

import android.os.Bundle;
import android.os.Handler;
import alliance.inappbilling.start.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class Main extends Activity {

	private Activity parentActivity;
	private BillingService mBillingService;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        parentActivity = this;
        
        Button btBuy = (Button) findViewById(R.id.buy);
        btBuy.setOnClickListener(new OnClickListener(){

			

			@Override
			public void onClick(View v) {

				Security.base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxB0nIEHj0qwusBGBSTj4NoiZXesEeWgqzhBiEC1/re7rtz6KXbOOxV0wu/mUGotiryrFcEXUNjvpaYDpwkwZzfhlGFTLmB0bby41TGwC96ynFQB79FtqZy49M2a8TsAHRfv0dC17ntxFG+sbSkgIAVWO4ZkNytiQFN1zP+P/jdL1YgG7gXL9zy4C1I/eIIQ80f/BCaIoA7cGAiEqBfDaOxqh0QU44Ntfl3XBeCSSwzHkibxkUkSyJ5P03JJkBjIDW/eeyX6RqAVePYHBaJ7xwYC113uNQPlyCxCp7sSyKEmv7GtksT6RG5mbuZ2l/KLHMWquCsj+pEY4PY80N5JQgwIDAQAB";
				
				String item = PurchaseItems.ITEM1_MANAGED.getItem();
            	String mPayloadContents = null;
            	
            	Handler mHandler = new Handler();
            	AlliancePurchaseObserver mPurchaseObserver = new AlliancePurchaseObserver(parentActivity, mHandler);
            	
            	mBillingService = new BillingService();
                mBillingService.setContext(parentActivity);
                
                ResponseHandler.register(mPurchaseObserver);
                boolean request = mBillingService.requestPurchase(item, Consts.ITEM_TYPE_INAPP, null);
                
//                if (!mBillingService.requestPurchase(item, null)) {
//                    showDialog(DIALOG_BILLING_NOT_SUPPORTED_ID);
//                }
                
//                ResponseHandler.register(mDungeonsPurchaseObserver);
//                if (!mBillingService.checkBillingSupported()) {
//                    showDialog(DIALOG_CANNOT_CONNECT_ID);
//                }
                
			}
        });
    }
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mBillingService.unbind();
    }
    
}
